package it.wyx.springbootkafkaclients.config;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author wyx
 * @version V 1
 * @Date 2022/10/30
 */
@Configuration
public class KafkaConfig {
	private static final String BROKER_LIST = "localhost:9092";

	@Bean
	public KafkaProducer stringProducer() {
		Properties properties = new Properties();
		// 连接地址
		properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BROKER_LIST);
		// 键的序列化方式
		properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
		// 值的序列化方式
		properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);

		return new KafkaProducer(properties);
	}
}
